package com.example.sm.mycook.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.sm.mycook.AddressActivity;
import com.example.sm.mycook.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class CartFragment extends Fragment implements View.OnClickListener {
    private View view;
    private TextView mCartLocation;
    private TextView mCartDelete;

    public CartFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_cart, container, false);

        initView(view);
        return view;
    }

    private void initView(View view) {
        mCartLocation = (TextView) view.findViewById(R.id.cart_location);
        mCartDelete = (TextView) view.findViewById(R.id.cart_delete);

        mCartLocation.setOnClickListener(this);
        mCartDelete.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cart_location:
                startActivityForResult(new Intent(getActivity(), AddressActivity.class),0);

                break;
            case R.id.cart_delete:

                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0 && resultCode == getActivity().RESULT_OK && data != null) {
            String address = data.getStringExtra("address");
            mCartLocation.setText(address);
        }
    }
}
